<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Log;


class WeChatController {

    public function index(){
        Log::info('request arrived.');
        $app = app('wechat.official_account');
        return $app->server->serve();
    }

    public function getJSSDKConfig (Request $request) {
        // dump(explode(',',$request->get('apis')));
        $arr = explode(',', $request->get('apis'));
        $debug = $request->get('debug') === 'true' ? true : false;
        $json = $request->get('json') === 'true' ? true : false;
        $url = $request->get('url');
        // dump($request->get('url'));
        // check
        if (!$url) {
            return response()->json(['status' => false, 'msg' => 'params error', 'data' => '']);
        }
        $app = app('wechat.official_account');
        dd($app);
        $app->jssdk->setUrl($url);
        $config = $app->jssdk->buildConfig($arr, $debug, $json, $url);
        return response($config);
    }
}
